package players;

import game.Cell;
import game.HexBoard;
import game.HexGame;

import java.awt.Color;

import javax.swing.JColorChooser;

public abstract class Player {
  
  private static int playerCount = 0;
  
  
  public static void resetPlayerCound() {
	  playerCount = 0;
  }

  
  private String name;
  private final Color color;


  /** Used to generate TempPlayers. */
  protected Player () {
    this(null, false);
  }
  
  
  protected Player (Color defaultColor) {
    this(defaultColor, true);
  }
  
  
  public Player(Color defaultColor, boolean chooseColor) {
    // The if case is for user players.
    this.name = "Player " + ++playerCount;
    if (chooseColor) { 
      this.color = JColorChooser.showDialog(null, "Select a color for " + name, defaultColor);
      if (color == null) System.exit(-1);
    }
    // The else case is for the EMPTY_CELL_PLAYER.
    else this.color = defaultColor; 
  }  


  /** The call to the actual player to make a move. 
   *  Must return a cell that has this player as its player (third argument).
   */
  public abstract Cell itsYourTurn(HexBoard hexBoard) ;


  /** Handle the call from the Game */
  public void itsYourTurn(HexGame hexGame, HexBoard hexBoardClone, String token) {
    hexGame.moveCheckIn(itsYourTurn(hexBoardClone), token);
  }
  

  public String getName() { return this.name; }

  
  public Color getColor() { return this.color; }
  
    
  @Override
  public String toString() {
    return getName() 
//           +  "(" + color.getRed() + ", " +  color.getGreen() + ", " + color.getBlue() + ")"
           ;
  }


  public void setName(String name) { this.name = name; }
  
  
}
